/*
 * @brief:
 * @Author: TzzzT
 * @Date: 2023-04-22 12:46:08
 * @LastEditTime: 2023-04-23 03:34:00
 * @LastEditors: TzzzT
 */

#pragma once

#include <stdint.h>
#include <string.h>

typedef struct lwrb
{
    uint8_t *buff; /*!< Pointer to buffer data. Buffer is considered initialized when `buff != NULL` and `size > 0` */
    size_t size;   /*!< Size of buffer data. Size of actual buffer is `1` byte less than value holds */
    size_t r;      /*!< Next read pointer. Buffer is considered empty when `r == w` and full when `w == r - 1` */
    size_t w;      /*!< Next write pointer. Buffer is considered empty when `r == w` and full when `w == r - 1` */
} lwrb_t;

int8_t lwrb_init(lwrb_t *rb, void *buffdata, size_t size);
size_t lwrb_peek(const lwrb_t *rb, void *data, size_t btp);
size_t lwrb_read(lwrb_t *rb, void *data, size_t btr);
size_t lwrb_write(lwrb_t *rb, const void *data, size_t btw);